<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Model;
use Think\Model;

/**
 * 文档基础模型
 */
class UcenterMemberModel extends Model{
    public function checkIsUserByOpenId($openid){
        $where['openid'] = $openid;
        $user = $this
        ->where($where)
        ->find();
        return $user;
    }

    public function register($nickname = '',$openid = '',$headimgurl = '' ){
        $data = array(
            'username'  => $nickname, 
            'openid'    => $openid,
            'headimgurl'=> $headimgurl,
            'reg_time'  => time(),
            );
        if($this->create($data)){
            $uid = $this->add();
            return $uid ? $uid : 0; //0-未知错误，大于0-注册成功
        }else {
            return $this->getError(); //错误详情见自动验证注释
        }
    }
    public function userInfo(){
        $uid = is_login();
        $where = array(
            'id'    => $uid,
            'status'=> 1,
            );
        $user_data = $this
        ->where($where)
        ->field('id,username,email,mobile,realname,identity,headimgurl')
        ->find();
        return $user_data;
    }
    public function editUserInfo($info){
        $uid = is_login();
        $where = array(
            'id'    => $uid,
            'status'=> 1,
            );
        $user_data = $this
        ->where($where)
        ->data($info)
        ->save();
        return $user_data;
    }
}
